package com.xyy.saas.payment.controller;

import com.alibaba.fastjson.JSON;
import com.xyy.saas.payment.manage.cores.vo.ResultPageVo;
import com.xyy.saas.payment.pojo.bo.QueryPlatformAccountViewBo;
import com.xyy.saas.payment.pojo.bo.WithdrawalRecordViewBo;
import com.xyy.saas.payment.service.PlatformAccountsManage;
import com.xyy.saas.payment.service.WithdrawalService;
import com.xyy.saas.payment.pojo.vo.PlatformAccountWithdrawalVo;
import com.xyy.saas.payment.pojo.vo.QueryPlatformAccountsVo;
import com.xyy.saas.payment.pojo.vo.WithdrawalRecordsVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.DependsOn;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;

/**
 * 管理平台报表接口
 * @date 2020/11/2 15:14
 */
@RestController
@RequestMapping("/withdrawal")
@DependsOn({"apolloUtil"})
public class WithdrawalController {

    private static Logger LOGGER = LoggerFactory.getLogger(WithdrawalController.class);

    @Autowired
    private WithdrawalService withdrawalService;

    @Autowired
    private PlatformAccountsManage platformAccountsManage;

    /**
     * 财务-业务账户查询
     */
    @PostMapping("/getAccounts")
    public ResultPageVo<List<QueryPlatformAccountViewBo>> getAccounts(@RequestBody QueryPlatformAccountsVo queryPlatformAccountsVo) {
        LOGGER.info("ReportController#getAccounts begin queryPlatformAccountsVo:{}", JSON.toJSONString(queryPlatformAccountsVo));
        ResultPageVo<List<QueryPlatformAccountViewBo>> queryPlatformAccountViewBos = null;
        try {
            queryPlatformAccountViewBos = platformAccountsManage.getAccountsByCondition(queryPlatformAccountsVo);
            LOGGER.info("WithdrawalController#getAccounts queryPlatformAccountsVo:{} queryPlatformAccountViewBos:{}", JSON.toJSONString(queryPlatformAccountsVo), JSON.toJSONString(queryPlatformAccountViewBos));
        } catch (Exception e) {
            LOGGER.error("WithdrawalController#getAccounts query error queryPlatformAccountsVo:{}", JSON.toJSONString(queryPlatformAccountViewBos),e);
        }
        return queryPlatformAccountViewBos;
    }

    /** 财务-业务账户提现 */
    @PostMapping("/accountWithdrawal")
    public ResultPageVo accountWithdrawal(@RequestBody PlatformAccountWithdrawalVo platformAccountWithdrawalVo) {
        LOGGER.info("WithdrawalController#accountWithdrawal begin platformAccountWithdrawalVo:{}", JSON.toJSONString(platformAccountWithdrawalVo));
        ResultPageVo resultPageVo= null;
        try {
            resultPageVo = withdrawalService.accountWithdrawal(platformAccountWithdrawalVo);
            LOGGER.info("WithdrawalController#accountWithdrawal platformAccountWithdrawalVo:{} resultPageVo:{}", JSON.toJSONString(platformAccountWithdrawalVo), JSON.toJSONString(resultPageVo));
        } catch (Exception e) {
            LOGGER.error("WithdrawalController#accountWithdrawal error queryPlatformAccountsVo:{}", JSON.toJSONString(platformAccountWithdrawalVo),e);
        }
        return resultPageVo;
    }

    /** 财务-业务账户提现明细 */
    @PostMapping("/records")
    public ResultPageVo<List<WithdrawalRecordViewBo>> records(@RequestBody WithdrawalRecordsVo withdrawalRecordsVo) {
        LOGGER.info("WithdrawalController#records begin withdrawalRecordsVo:{}", JSON.toJSONString(withdrawalRecordsVo));
        ResultPageVo<List<WithdrawalRecordViewBo>> resultPageVo= null;
        try {
            resultPageVo = withdrawalService.queryAccountWithdrawalRecords(withdrawalRecordsVo);
            LOGGER.info("WithdrawalController#records withdrawalRecordsVo:{} resultPageVo:{}", JSON.toJSONString(withdrawalRecordsVo), JSON.toJSONString(resultPageVo));
        } catch (Exception e) {
            LOGGER.error("WithdrawalController#records error withdrawalRecordsVo:{}", JSON.toJSONString(withdrawalRecordsVo),e);
        }
        return resultPageVo;
    }


}
